package main

import (
	"fmt"
	"time"
)

func main() {

	// 定义一个int channel
	intChan := make(chan int, 1)
	// 定义一个匿名协程， 休眠3s
	go func() {
		defer close(intChan)
		time.Sleep(30 * time.Second)
		intChan <- 1
	}()

	// 定义一个string channel
	stringChan := make(chan string, 1)
	// 定义一个匿名协程， 休眠5s
	go func() {
		defer close(stringChan)
		time.Sleep(12 * time.Second)
		stringChan <- "Hello World"
	}()

	// 编写select
	select {
	case i := <-intChan:
		fmt.Println("Received  intChan -> ", i)
	case s := <-stringChan:
		fmt.Println("Received stringChan -> ", s)
	default:
		fmt.Println("Nothing received")
	}

}
